/**
 * 孤儿进程
 *     父进程结束，子进程就成为孤儿进程，会由1号进程(init进程)领养。
*/

#include <stdio.h>
#include <stdlib.h>

#include <unistd.h>

int main(void)
{

    pid_t pid = fork();
    if (0 > pid)
    {
        perror("fork error: ");
        exit(EXIT_FAILURE);
    }
    else if (0 < pid)
    {
        sleep(1);
        exit(1);
    }
    else
    {
        printf("I am child progess is id %d, ppid is %d\n", getpid(), getppid());
        sleep(3);
        printf("I am child progess is id %d, ppid is %d\n", getpid(), getppid());
    }

    return 0;
}